package com.sinosoft.msf.base.supplier.controller;

import cn.hutool.core.lang.Validator;
import com.alibaba.fastjson.JSONObject;
import com.sinosoft.msf.base.supplier.pojo.CompanyQueryReqPojo;
import com.sinosoft.msf.base.supplier.pojo.OptVo;
import com.sinosoft.msf.base.supplier.pojo.RestEntity;
import com.sinosoft.msf.base.supplier.service.CommonBizService;
import com.sinosoft.msf.base.supplier.service.CompanyNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangzhihao
 **/
@RestController
@RequestMapping("/company")
public class CompanyNoticeController {

    @Autowired
    CompanyNoticeService companyNoticeService;
    @Autowired
    CommonBizService bizService;

    private OptVo curentOpt() {
        return bizService.queryCureUserInfo();
    }

    @PostMapping(value = "/notice/warnList", name = "消息提醒查询")
    public RestEntity markNoticeWarnList(@RequestBody CompanyQueryReqPojo companyQueryReqPojo) {
        return RestEntity.data(companyNoticeService.markWarnList(companyQueryReqPojo));
    }

    @PostMapping(value = "/notice/read", name = "消息已读")
    public RestEntity markNoticeRead(@RequestBody JSONObject jsonObject) {
        String id = jsonObject.getString("id");
        Validator.validateNotEmpty(id, "消息id不可为空");
        String type = jsonObject.getString("type");
        Validator.validateNotEmpty(type, "操作类型不可为空");
        OptVo optVo = curentOpt();
        companyNoticeService.markNoticeRead(jsonObject, optVo);
        return RestEntity.success();
    }

    @PostMapping(value = "/notice/generate", name = "消息生成")
    public RestEntity markNoticeGenerate(@RequestBody JSONObject jsonObject) {
        companyNoticeService.markNoticeGenerate(jsonObject);
        return RestEntity.success();
    }

    @PostMapping(value = "/notice/ipDetail", name = "相同ip地址详情")
    public RestEntity noticeIpDetail(@RequestBody JSONObject jsonObject) {
        String id = jsonObject.getString("id");
        Validator.validateNotEmpty(id, "消息id不可为空");
        return RestEntity.data(companyNoticeService.noticeIpDetail(jsonObject));
    }

    @PostMapping(value = "/notice/personDetail", name = "相同人员信息详情")
    public RestEntity noticePersonDetail(@RequestBody JSONObject jsonObject) {
        String id = jsonObject.getString("id");
        Validator.validateNotEmpty(id, "消息id不可为空");
        return RestEntity.data(companyNoticeService.noticePersonDetail(jsonObject));
    }
}